<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
<div id="root">
<h1>今天天气很{{info}}</h1>
    <button @click="changeWeather">切换天气</button>
</div>
</body>
<script type="text/javascript">
  const vm = new Vue({
    el: '#root',
    data: function () {
      return {
        isHot:true
      }
    },
    computed:{
      info(){
        return this.isHot ? '炎热' : '凉爽'
      }
    },
    methods:{
      changeWeather(){
        this.isHot = !this.isHot
      }
    },
    watch:{
      isHot:{
        //当isHot发生改变时,handler函数被调用
        handler(newValue,oldValue) {
            console.log("isHot被修改了")
          console.log(oldValue+"修改成了"+newValue)
        }
      }
    }
  })
</script>
</html>